#ifndef __CALL_RECORD_OP_H__ 
#define __CALL_RECORD_OP_H__

#include <interface/data_op/call_record.h>

namespace aot{ namespace data{

class call_record_info_impl : public icall_record_info
{
public:
    virtual ~call_record_info_impl(){;}
    call_record_info_impl()
    {
        id = 0;
        call_state = 0;
        call_channel = 0;
		flag = 0;

        phone_number = &phone_number_impl;
        call_datetime = &call_datetime_impl;
        call_short_time = &call_short_time_impl; 
        call_time = &call_time_impl;
        record_file = &record_file_impl;
        nickname = &nickname_impl;
        user_id = &user_id_impl;
		title = &title_impl;
        remark = &remark_impl;
    }
public:
    virtual  bool clone(icall_record_info** out) 
    {
        call_record_info_impl* p = new call_record_info_impl();
        *out = p;
        return p->assign(this);
    }
    virtual  bool assign(const icall_record_info* in) 
    {
        if (NULL==in)
            return false;

        call_record_info_impl* p = (call_record_info_impl*) in;
        *this = *p;

        phone_number = &phone_number_impl;
        call_datetime = &call_datetime_impl;
        call_time = &call_time_impl;
        call_short_time = &call_short_time_impl;  
        record_file = &record_file_impl;
        nickname = &nickname_impl;
        user_id = &user_id_impl;
		title = &title_impl;
        remark = &remark_impl;

		id = in->id;
		call_state = in->call_state;
		call_channel = in->call_channel;
		flag = in->flag;
        return true;
    }
public:
    aot::tt::str_impl phone_number_impl;
    aot::tt::str_impl call_datetime_impl;
    aot::tt::str_impl call_time_impl;
    aot::tt::str_impl call_short_time_impl;
    aot::tt::str_impl record_file_impl;
    aot::tt::str_impl nickname_impl;
    aot::tt::str_impl user_id_impl;
	aot::tt::str_impl title_impl;
    aot::tt::str_impl remark_impl;
};

class call_record_op_impl : public aot::data::icall_record_op
{
public:
    call_record_op_impl(void);
    virtual ~call_record_op_impl(void);
public:    
    virtual bool insert(const icall_record_info* p, int* new_id);
    virtual bool del(int id);
	virtual bool del_by_user_id(const char* user_id);
    virtual bool del_by_state(int state);
	virtual bool del_record_file(int id);
    virtual bool update(const icall_record_info* p);
    virtual bool read(int id, isqlite3_table** out);
    virtual bool read(int id, icall_record_info* out);
    virtual bool read(int id, icall_record_info** out);
    virtual bool get_records_by_state(int state, isqlite3_table** out);
	virtual bool get_records_by_state(int state, int get_count, isqlite3_table** out);
    virtual bool get_records_by_call_num(const char* phone_num, isqlite3_table** out);
    
    virtual int get_count_by_state(int state);
    virtual bool get_page_records_by_state(long state, int count_per_page, int page_index, isqlite3_table** out);

    virtual int get_count_by_user_id(const char* user_id);
    virtual bool get_page_records_by_user_id(const char* user_id, int count_per_page, int page_index, isqlite3_table** out);

    virtual int get_count_by_nickname(const char* nickname);
    virtual bool get_page_records_by_nickname(const char* nickname, int count_per_page, int page_index, isqlite3_table** out);

    virtual int get_count_by_phone_number(const char* phone_number);
    virtual bool get_page_records_by_phone_number(const char* phone_number, int count_per_page, int page_index, isqlite3_table** out);
	virtual bool change_state(long old_state, long new_state);

	virtual int get_count_by_flag(ecall_flag flag);
	virtual bool change_flag(ecall_flag old_flag, ecall_flag new_flag);
};

}} /* end namespace aot/data*/

#endif // __CALL_RECORD_OP_H__
